package cn.openea.perpartner.meily.web.entity.dto;

import cn.openea.perpartner.common.core.annotation.Excel;
import cn.openea.perpartner.meily.constant.enums.GoodsTypeEnums;
import cn.openea.perpartner.meily.web.entity.Goods;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.function.Function;

/**
 * @author ysk
 * @version 1.0.1
 * @Description 商品DTO
 * @createTime 2023年05月05日 16:53:00
 */
@Component
public class GoodsDTOFactory {

    @Data
    @SuperBuilder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class GoddsExportExcelDTO {
        @Excel(name = "商品ID")
        private Long goodsId;
        @Excel(name = "商品编号")
        private String goodsNo;
        @Excel(name = "商品类型")
        private String goodsType;
        @Excel(name = "商品名称")
        private String goodsName;
        @Excel(name = "商品主图")
        private String goodsImages;
        @Excel(name = "商品分类")
        private String category;
        @Excel(name = "商品标签")
        private String goodsTag;
        @Excel(name = "商品规格")
        private String specification;
        @Excel(name = "商品状态")
        private String status;
        @Excel(name = "销量")
        private String customSales;
        @Excel(name = "所属品牌")
        private String brand;
        @Excel(name = "发货链接")
        private String shippingLink;
    }


    public Function<Goods, GoddsExportExcelDTO> toExportExcelDTO = (goods) -> {
        if (goods == null) {
            return null;
        }
        GoddsExportExcelDTO exportExcelDTO = new GoddsExportExcelDTO();
        BeanUtils.copyProperties(goods, exportExcelDTO);
        GoodsTypeEnums instance = GoodsTypeEnums.getInstance(goods.getGoodsType());
        if (instance == null){
            exportExcelDTO.setGoodsType("");
        }else {
            exportExcelDTO.setGoodsType(instance.getRemark());
        }
        // 商品主图只取一个
        return exportExcelDTO;
    };
}
